<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctxPath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>数据列表</title>
    <link rel="stylesheet" href="${ctxPath}/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPath}/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPath}/layuiadmin/modules/ext/soulTable.css" media="all">
    <%--body渲染--%>
    <style>
        body{margin: 10px;}
        input.layui-input{height:30px}
        input.layui-form-select{padding-right:0px}
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="">
        <div class="layui-row">
            <div class="layui-col-md2">
                <!-- 左边 开始-->
                <div id="menuTreeId"></div>
                <!-- 左边 结束-->
            </div>
            <div class="layui-col-md10">
                <!-- 右边 开始 -->
                <!-- 友链数据列表 -->
                <div class="flinkTable">
                    <%--数据表格--%>
                    <table class="layui-hide" id="demo" lay-filter="demo"></table>
                </div>
                <!-- 右边 结束-->
            </div>
        </div>
    </div>
</div>
<%--表内工具栏--%>
<script type="text/html" id="toolBar">
    <shiro:hasPermission name="sysuser:update">
        <a class="layui-btn layui-btn-normal layui-btn-xs layui-btn-radius" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="sysuser:delete">
        <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-radius" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
    </shiro:hasPermission>
</script>
<%--头部工具栏--%>
<script type="text/html" id="headToolBar">
    <div class="layui-inline">
        <div class="layui-btn-group">
            <shiro:hasPermission name="sysuser:add">
                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-event="add">
                    <i class="layui-icon">&#xe654;</i>
                </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="sysuser:update">
                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-event="update">
                    <i class="layui-icon">&#xe642;</i>
                </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="sysuser:delete">
                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-event="delete">
                    <i class="layui-icon">&#xe640;</i>
                </button>
            </shiro:hasPermission>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-event="reload">
                <i class="layui-icon">&#xe669;</i>
            </button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-event="clear">
                <i class="layui-icon">&#xe60e;</i>
            </button>
        </div>
    </div>
</script>
<script src="${ctxPath}/layuiadmin/layui/layui.js"></script>
<script src="${ctxPath}/js/jquery-1.11.1.min.js"></script>
<script src="${ctxPath}/js/layui-customtips.js"></script>
<!-- layui代码 -->
<script>
    //ran防止懒惰，r随机动画
    {var ran = Math.random();
        var r=Math.floor(Math.random()*6);}
    //自定义模块
    layui.config({
        base: '${ctxPath}layuiadmin/modules/ext/',   // 第三方模块所在目录
        version: 'v1.5.19' // 插件版本号
    })
        .extend({
            soulTable: 'soulTable',
            tableChild: 'tableChild',
            tableMerge: 'tableMerge',
            tableFilter: 'tableFilter',
            excel: 'excel',
            treeSelect:'treeSelect',
            treetable:'treetable'
        });
    //使用模块
    layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel',
            'upload', 'element', 'slider','soulTable','treeSelect',
            'treetable','tree']
        ,function(){
//声明模块变量
            {var laydate = layui.laydate
                ,laypage = layui.laypage
                ,layer = layui.layer
                ,table = layui.table
                ,carousel = layui.carousel
                ,upload = layui.upload
                ,element = layui.element
                ,slider = layui.slider
                ,admin = layui.admin
                ,form = layui.form
                ,soulTable=layui.soulTable
                ,treeSelect=layui.treeSelect
                ,tree=layui.tree
                ,$ = layui.$;}
//渲染表格方法
            var renderSoulTable =function(){
                table.render({
                    elem: '#demo'
                    ,id:'demo'
                    ,height: 'full-100'
                    ,url: '${ctxPath}/getDataBySysMenu?ran='+ ran
                    ,title: '角色表'
                    ,page: true
                    ,toolbar: '#headToolBar'
                    ,totalRow: false //{ps} 开启合计行
                    ,limit:20
                    ,limits:[10,20,30,50,100,200,500,1000,2000]
                    ,cellMinWidth:80
                    ,cols: [[
                        {type: 'checkbox',fixed:'left'},
                        {field: 'id', title: 'ID', width:100, sort: true},
                        {field: 'title', title: '标题',sort:true,edit:'text',filter:true},
                        {field: 'pid', title: '父ID',sort:true,filter:true},
                        {field: 'icon', title: '图标',sort:true,edit:'text',filter:true},
                        {field: 'href', title: '地址',sort:true,edit:'text',filter:true},
                        {field: 'spread', title: '展开',sort:true,edit:'text',filter:true},
                        {field: 'sort', title: '排序',sort:true,edit:'text',filter:true},
                        {field: 'is_top', title: '置顶',sort:true,edit:'text',filter:true},
                        {field: 'del_flag', title: '删除标识',sort:true,edit:'text',filter:true,hide:true},
                        {field: 'level', title: '级别',sort:true,edit:'text',filter:true},
                        {field: 'type', title: '类型',sort:true,edit:'text',filter:true},
                        {field: 'permission', title: '权限标识',sort:true,filter:true},
                        {fixed: 'right',align:'center',title:'***',templet: '<div><i class="layui-icon layui-icon-snowflake layui-drag" /></div>',minWidth:50,maxWidth:50,width:50},
                        {fixed: 'right', title:'操作', align:'center', toolbar: '#toolBar',minWidth:285}
                    ]]
                    ,initSort:{
                        field:'id',
                        type:'asc',
                    }
                    ,filter: {
                        items:['column','data','condition','editCondition','excel','clearCache'],
                        cache: true
                    }
                    ,overflow: {
                        type: 'tips'
                        ,hoverTime: 300
                        ,color: 'black'
                        ,bgColor: 'white'
                        ,minWidth: 500
                        ,maxWidth: 1000
                    }
                    ,contextmenu: {
                        header: [
                            {
                                name: '复制',
                                icon: 'layui-icon layui-icon-template',
                                click: function(obj) {
                                    soulTable.copy(obj.text)
                                    layer.msg('复制成功', {icon: 1, time: 1000})
                                }
                            },
                            {
                                name: '导出excel',
                                click: function() {
                                    soulTable.export(this.id)
                                }
                            },
                            {
                                name: '重载表格',
                                icon: 'layui-icon layui-icon-refresh-1',
                                click: function() {
                                    table.reload(this.id);
                                }
                            },
                            {
                                name: '清除缓存',
                                icon: 'layui-icon layui-icon-log',
                                click: function() {
                                    layer.confirm('清除缓存会使显示风格还原，确认？',{icon:3,title:'提示信息'}, function(index){
                                        soulTable.clearCache("demo");
                                        layer.msg('已清缓存', {icon: 1, time: 1000});
                                    });
                                }
                            },
                            {
                                name: '字体颜色',
                                icon: 'layui-icon layui-icon-theme',
                                children: [
                                    {
                                        name: '大红色',
                                        click: function(obj) {
                                            obj.elem.css('color', '#aa0200')
                                        }
                                    },
                                    {
                                        name: '海蓝色',
                                        click: function(obj) {
                                            obj.elem.css('color', '#1000aa')
                                        }
                                    },
                                    {
                                        name: '柑橘色',
                                        click: function(obj) {
                                            obj.elem.css('color', '#aa6d00')
                                        }
                                    },
                                    {
                                        name: '翠绿色',
                                        click: function(obj) {
                                            obj.elem.css('color', '#00aa22')
                                        }
                                    }
                                    ,
                                    {
                                        name: '还原字体',
                                        click: function(obj) {
                                            obj.elem.css('color', '')
                                        }
                                    }
                                ]
                            }
                            ,
                            {
                                name: '背景色',
                                icon: 'layui-icon layui-icon-theme',
                                children: [
                                    {
                                        name: '浅海蓝',
                                        click: function(obj) {
                                            obj.elem.css('background', '#00caed')
                                        }
                                    },
                                    {
                                        name: '鲜花红',
                                        click: function(obj) {
                                            obj.elem.css('background', '#ed8670')
                                        }
                                    },
                                    {
                                        name: '草原绿',
                                        click: function(obj) {
                                            obj.elem.css('background', '#99ed48')
                                        }
                                    },
                                    {
                                        name: '香蕉黄',
                                        click: function(obj) {
                                            obj.elem.css('background', '#f7ff50')
                                        }
                                    },
                                    {
                                        name: '还原背景',
                                        click: function(obj) {
                                            obj.elem.css('background', '')
                                        }
                                    }
                                ]
                            }
                        ],
                        body: [
                            {
                                name: '复制',
                                icon: 'layui-icon layui-icon-template',
                                click: function(obj) {
                                    soulTable.copy(obj.text)
                                    layer.msg('复制成功', {icon: 1, time: 1000})
                                }
                            },
                            {
                                name: '删除当前行数据',
                                click: function(obj) {
                                    layer.confirm('删除\''+obj.row.name+'\'吗',{icon:3,title:'提示信息'}, function(index){
                                        del( obj.row.id );
                                    });
                                }
                            },
                            {
                                name: '编辑数据',
                                click: function(obj) {
                                    edit(obj.row.id);
                                }
                            },
                            {
                                name: '隐藏当前行数据',
                                click: function(obj) {
                                    obj.del();
                                }
                            },
                            {
                                name: '字体颜色',
                                icon: 'layui-icon layui-icon-theme',
                                children: [
                                    {
                                        name: '大红色',
                                        click: function(obj) {
                                            obj.elem.css('color', '#aa0200')
                                        }
                                    },
                                    {
                                        name: '海蓝色',
                                        click: function(obj) {
                                            obj.elem.css('color', '#1000aa')
                                        }
                                    },
                                    {
                                        name: '柑橘色',
                                        click: function(obj) {
                                            obj.elem.css('color', '#aa6d00')
                                        }
                                    },
                                    {
                                        name: '翠绿色',
                                        click: function(obj) {
                                            obj.elem.css('color', '#00aa22')
                                        }
                                    },
                                    {
                                        name: '还原字体',
                                        click: function(obj) {
                                            obj.elem.css('color', '')
                                        }
                                    }
                                ]
                            },
                            {
                                name: '单-背景色',
                                icon: 'layui-icon layui-icon-theme',
                                children: [
                                    {
                                        name: '浅海蓝',
                                        click: function(obj) {
                                            obj.elem.css('background', '#00caed')
                                        }
                                    },
                                    {
                                        name: '鲜花红',
                                        click: function(obj) {
                                            obj.elem.css('background', '#ed8670')
                                        }
                                    },
                                    {
                                        name: '草原绿',
                                        click: function(obj) {
                                            obj.elem.css('background', '#99ed48')
                                        }
                                    },
                                    {
                                        name: '香蕉黄',
                                        click: function(obj) {
                                            obj.elem.css('background', '#f7ff50')
                                        }
                                    },
                                    {
                                        name: '还原单背景',
                                        click: function(obj) {
                                            obj.elem.css('background', '')
                                        }
                                    }
                                ]
                            },
                            {
                                name: '行-背景色',
                                icon: 'layui-icon layui-icon-theme',
                                children: [
                                    {
                                        name: '浅海蓝',
                                        click: function(obj) {
                                            obj.trElem.css('background', '#00caed')
                                        }
                                    },
                                    {
                                        name: '鲜花红',
                                        click: function(obj) {
                                            obj.trElem.css('background', '#ed8670')
                                        }
                                    },
                                    {
                                        name: '草原绿',
                                        click: function(obj) {
                                            obj.trElem.css('background', '#99ed48')
                                        }
                                    },
                                    {
                                        name: '香蕉黄',
                                        click: function(obj) {
                                            obj.trElem.css('background', '#f7ff50')
                                        }
                                    },
                                    {
                                        name: '还原行背景',
                                        click: function(obj) {
                                            obj.trElem.css('background', '')
                                        }
                                    }
                                ]
                            }
                        ]}
                    ,soulSort:true
                    ,excel:{
                        on: true,
                        filename: '数据.xlsx',
                        head:{
                            family: 'Calibri',
                            size: 16,
                            color: '000000',
                            bgColor: 'C7C7C7'
                        },
                        font: { // 正文样式
                            family: 'Calibri',
                            size: 12,
                            color: '000000',
                            bgColor: 'ffffff'
                        }
                    }
                    ,rowDrag: {trigger: '.layui-drag'}
                    ,drag: {toolbar: true}
                    ,text:'对不起，加载出现异常！请联系小蓝解决！'
                    ,done: function(res, curr, count){
                        soulTable.render(this);
                        if (res.count == 0) {
                            $(".layui-none").hide();//隐藏无数据
                            $(".layui-table-page").hide();//隐藏分页
                        }
                    }
                });
            }
//执行渲染表格方法
            renderSoulTable();
//监听Tab切换
            element.on('tab(demo)', function(data){
                layer.tips('切换了 '+ data.index +': '+ this.innerHTML, this, {
                    tips: 1
                });
            });
//监听头工具栏事件
            table.on('toolbar(demo)', function(obj){
                var checkStatus = table.checkStatus(obj.config.id)
                    ,data = checkStatus.data; //获取选中的数据
                switch(obj.event){
                    case 'add':
                        layer.open({
                            type: 2
                            ,id:"onlyone"
                            ,content: '${ctxPath}/toSysMenuAdd'
                            ,shade:0
                            ,shadeClose: false
                            ,moveOut:false
                            ,area: ['80%', '80%']
                            ,maxmin: true
                            ,anim:r
                            ,title:'创建'
                        });
                        break;
                    case 'update':
                        if(data.length === 0){
                            layer.msg('请选择一行',{icon:2,time:2000,offset:'20px'});
                        }  else if(data.length > 1){
                            layer.msg('只能编辑一行',{icon:2,time:2000,offset:'20px'});
                        }  else {
                            edit( checkStatus.data[0].id );
                        }
                        break;
                    case 'delete':
                        if(data.length === 0){
                            layer.msg('请选择一行',{icon:2,time:2000,offset:'20px'});
                        } else{
                            var arrayName=[];
                            for(var i=0;i<data.length;i++){
                                arrayName.push(data[i].name);
                            }
                            layer.confirm('删除'+arrayName.toString()+'吗',{icon:3,title:'提示信息'}, function(index){
                                var arrayId=[];
                                for(var i=0;i<data.length;i++){
                                    arrayId.push(data[i].id);
                                }
                                dels( arrayId );
                            });
                        }
                        break;
                    case 'reload':
                        $('#searchName').val("");
                        layer.msg('已重载', {icon: 1, time: 1000})
                        reloadPage();
                        break;
                    case 'clear':
                        layer.confirm('清除缓存会使显示风格还原，确认？',{icon:3,title:'提示信息'}, function(index){
                            soulTable.clearCache("demo");
                            layer.msg('已清缓存', {icon: 1, time: 1000});
                        });
                        break;
                    case 'search':
                        reloadPage();
                        break;
                };
            });
//监听行工具事件
            table.on('tool(demo)', function(obj){
                var data = obj.data
                    , layEvent = obj.event;
                if(layEvent === 'del'){
                    layer.confirm('删除\''+data.name+'\'吗',{icon:3,title:'提示信息'}, function(index){
                        del( data['id'] );
                    });
                } else if(layEvent === 'edit'){
                    edit( data['id'] );
                } else if(layEvent === 'root'){
                    renderTree(obj.data.id,obj.data.name);
                } else if(layEvent === 'disable'){
                    disuseable(obj.data);
                } else if(layEvent === 'able'){
                    useable(obj.data);
                }
            });
//监听单元格编辑
            <shiro:hasPermission name="sysuser:update">
            table.on('edit(demo)', function(obj){
                var value = obj.value //得到修改后的值
                    ,_data = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
                $.ajax({
                    url:'${ctxPath}/findSysRoleById', /* 数据接口 */
                    type:'post',
                    data:{id:_data.id},
                    dataType:'json',
                    success:function( data ){
                        if( data['code']=='0' ){
                            var _data =data['data'];
                            _data[field]=value;
                            console.log( _data );
                            $.ajax({
                                url:'${ctxPath}/updateBySysRolePrimaryKey',
                                type:'post',
                                data:_data,
                                dataType:'json',
                                success:function( data ){
                                    var code = data['code'];
                                    layer.closeAll();
                                    if(code=='0'){
                                        layer.msg('更新'+ _data['name'] +'成功',{icon:1,time:2000,offset:'20px'});
                                    }else{
                                        layer.msg('更新'+ _data['name'] +'失败, 原因: '+ data['msg'],{icon:2,time:2000,offset:'20px'});
                                    }
                                }
                            });
                        }else{
                            layer.msg('访问数据错误。');
                        }
                    }
                });
            });
            </shiro:hasPermission>
//监听行双击事件
            <shiro:hasPermission name="sysuser:update">
            table.on('rowDouble(demo)', function(obj){
                edit( obj.data.id );
            });
            </shiro:hasPermission>
//监听弹层提交事件
            form.on('submit(layer-submit)', function(data){
                save();
                return false;
            });
//验证规则
            form.verify({
                pass: [/(.+){3,16}$/, '密码必须3到16位']
            });
            //定义一个方法，此方法用于显示菜单树形结构
            var renderTree= function() {
                tree.render({
                    elem: '#menuTreeId'
                    ,data: getMenuTreeData()
                    ,id: 'menuTreeId'
                    ,click: function(obj){
                        table.reload("demo",{
                            where: {
                                id:obj.data.id
                            }
                        })
                    }
                });
            };

            function getMenuTreeData()
            {
                var data=[];
                //发送异步请求（ajax）
                $.ajax(
                    {
                        url: "/getMenuDataTreeJson",
                        type: "post",
                        async:false,
                        success:function (result) {
                            data=result;
                        }

                    }
                );
                return data;
            };

            //初始化树形结构
            renderTree();

        });

</script>

<!-- 我们的业务代码 -->
<script>
    //修改
    function edit( id ){
        $.ajax(
            {
                url:'${ctxPath}/findSysRoleById',
                type:'post',
                data:{id:id},
                dataType:'json',
                success:function( data ){
                    if( data['code']=='0' ){
                        createEditLayer( data.data );
                    }else{
                        layer.msg('访问数据错误',{icon:2,time:2000,offset:'20px'});
                    }
                }
            }
        );
    }
    //创建修改弹层操作
    function createEditLayer( data ){
        //HTMl编辑
        {var HTML="<div class=\"layui-fluid\">"+
            "<div class=\"layui-card\">"+
            "<div class=\"layui-card-header\" >"+
            "<div class=\"layui-input-inline\" lay-value=\""+data['id']+"\">"+data['name']+"</div>"+
            "</div>"+
            "<div class=\"layui-card-body\" style=\"padding: 15px;\">"+
            "<form class=\"layui-form\" action=\"\" lay-filter=\"component-form-group\">"+
            "<div class=\"layui-col-md6 layui-col-sm12\">"+
            "<div class=\"layui-form-item\">"+
            "<label class=\"layui-form-label\">ID</label>"+
            "<div class=\"layui-input-inline\">"+
            "<input value='"+data['id']+"' type=\"text\" id=\"id\" name=\"id\" lay-verify=\"required\" placeholder=\""+data['name']+"的ID\" autocomplete=\"off\" class=\"layui-input\" readonly>"+
            "</div>"+
            "<div class=\"layui-form-mid layui-word-aux\">只读</div>"+
            "</div>"+
            "</div>"+

                "<div class=\"layui-col-md6 layui-col-sm12\">"+
                "<div class=\"layui-form-item\">"+
                "<div class=\"layui-inline\">"+
                "<label class=\"layui-form-label\">登录名</label>"+
                "<div class=\"layui-input-inline\">"+
                "<input type=\"text\" id=\"name\" name=\"name\" value='"+data['name']+"' class=\"layui-input\" lay-verify=\"required\" autocomplete=\"on\"/>"+
                "</div>"+
                "</div>"+
                "</div>"+
                "</div>"+

                "<div class=\"layui-col-md6 layui-col-sm12\">" +
                "<div class=\"layui-form-item\">" +
                "<label class=\"layui-form-label\">状态</label>" +
                "<div class=\"layui-input-inline\">" +
                "<select id=\"useable\" name=\"useable\" lay-verify=\"required\" value='"+data['useable']+"' lay-search=\"\">" +
                "</select>"+
                "</div>" +
                "</div>" +
                "</div>"+

                "<div class=\"layui-form-item\">"+
                "</div>"+
                "<div class=\"layui-form-item\">" +
                "<div class=\"layui-layer-btn layui-layer-btn-c\">" +
                "<button class=\"layui-btn\" lay-submit=\"\" lay-filter=\"layer-submit\">保存修改</button>" +
                "</div>"+
                "</div>"+
                "</form>"+
                "</div>"+
                "</div>"+
                "</div>";}
        layer.open({
            type: 1
            ,title: '编辑'
            ,closeBtn: false
            ,skin: 'layui-layer-rim'
            ,area: ['80%','80%']
            ,shadeClose: true
            ,id: 'layui-edit-only'
            ,btnAlign: 'c'
            ,moveType: 1
            ,content: HTML
            ,anim:r
            ,success: function( layero ){
                var HTML2="<option value=\"\">直接选择或搜索选择</option>";
                var arr=["可用","不可用"];
                for(var i=0;i<arr.length;i++){
                    HTML2+="<option value=\""+i+"\"";
                    if(data['useable']==i) HTML2+=" selected";
                    HTML2+=">"+arr[i]+"</option>";
                }
                $("#useable").append(HTML2);
                layui.use('form', function(){
                    var form = layui.form;
                    form.render();
                });
            }
        });
    }
    //单个删除
    function del( _id){
        var table=layui.table;
        $.ajax({
            url:'${ctxPath}/deleteSysRoleById',
            type:'post',
            data:{id:_id},
            dataType:'json',
            success:function( data ){
                var code = data['code'];
                layer.closeAll();
                if(code=='0'){
                    layer.msg('删除：'+_id+'成功',{icon:1,time:2000,offset:'20px'});
                    reloadPage();
                }else{
                    layer.msg('删除:'+_id+'失败, 原因:'+ data['msg'],{icon:2,time:2000,offset:'20px'});
                }
            }
        });
    }
    //批量删除
    function dels( _ids){
        var table=layui.table;
        var _id=_ids.toString();
        $.ajax({
            url:'${ctxPath}/deleteSysRolesById',
            type:'post',
            data:{ids:_id},
            dataType:'json',
            success:function( data ){
                var code = data['code'];
                layer.closeAll();
                if(code=='0'){
                    layer.msg('删除：'+_id+'成功',{icon:1,time:2000,offset:'20px'});
                    reloadPage();
                }else{
                    layer.msg('删除:'+_id+'失败, 原因:'+ data['msg'],{icon:2,time:2000,offset:'20px'});
                }
            }
        });
    }
    //重载本页面
    function reloadPage(){
        var table=layui.table;
        var soulTable=layui.soulTable;
        table.reload('demo', {
            where: {},
            done:function(res){
                soulTable.render(this);
            }
        });
    }
    //更新前的收集items名字
    var items = [
        "id", "name", "useable"
    ];
    //更新前的收集
    function pickData(){
        var obj = {};
        for( var i=0; i<items.length; i++ ){
            var val = $("#"+ items[i]).val().split('||')[0];
            obj[ items[i] ] = val;
        }
        return obj;
    }
    //更新
    function save(){
        var _data = pickData();
        $.ajax({
            url:'${ctxPath}/updateBySysRolePrimaryKey',
            type:'post',
            data:_data,
            dataType:'json',
            success:function( data ){
                var code = data['code'];
                layer.closeAll();
                if(code=='0'){
                    layer.msg('更新'+_data['name']+'成功',{icon:1,time:2000,offset:'20px'});
                    reloadPage();
                }else{
                    layer.msg('更新'+_data['name'] +'失败, 原因:'+ data['msg'],{icon:2,time:2000,offset:'20px'});
                }
            }
        });
    }
</script>
</body>
</html>

